<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">

      <el-form-item label="姓名" prop="name">
        <el-input v-model="queryParams.name" placeholder="请输入职位名称" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="电话" prop="telephone">
        <el-input v-model="queryParams.telephone" placeholder="电话" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="性别要求">
        <el-select v-model="queryParams.sex" placeholder="请选择">
          <el-option v-for="dict in sexOptions" :key="dict.dictValue" :label="dict.dictLabel"
            :value="dict.dictValue"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="hireList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="应聘职位名称" align="center" prop="title">
      </el-table-column>
      <el-table-column label="姓名" align="center" prop="name">
      </el-table-column>
      <el-table-column label="电话" align="center" prop="telephone" width="180">
      </el-table-column>
      <el-table-column label="性别" align="center" prop="sex" width="180">
  
          <template slot-scope="scope">
            {{ selectDictLabel(sexOptions, scope.row.sex) }}
          </template>
   
      </el-table-column>
      <el-table-column label="身份证号" align="center" prop="idCard" width="180">
      </el-table-column>
      <el-table-column label="是否录用" align="center" prop="hireStatus" width="180">
        <template slot-scope="scope">
          <el-switch v-model="scope.row.hireStatus" :active-value="1" :inactive-value="0"
            @change="handleHireStatusChange(scope.row)" />
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">

          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
            v-hasPermi="['hire:hireUser:remove']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 添加或修改活动任务管理对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="50%" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="姓名">
              <el-input v-model="form.name" placeholder="请输入内容"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>

// import ImageUpload from '@/components/ImageUpload';
import { listHirePeople, getHirePeople, addHirePeople, updateHirePeople, delHirePeople, exportHirePeople } from "@/api/hire/hireUser";
export default {
  name: "HireUser",
  // components: {
  //   // ImageUpload
  // },
  data() {
    return {
      // 遮罩层s
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 活动任务管理表格数据
      hireList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: null,
        telephone: null,
        sex:null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
      sexOptions: [],
      hireStatusOptions: []
    };
  },
  created() {
    this.getList();
    this.getDicts("sys_user_sex").then(response => {
      this.sexOptions = response.data;
    });

    this.getDicts("hire_status").then(response => {
      this.hireStatusOptions = response.data;
    });


  },
  methods: {
    handleHireStatusChange(data) {
      console.log(data)
      updateHire(data).then(response => {
        this.msgSuccess("修改成功");
        this.getList();
      });
    },
    /** 查询活动任务管理列表 */
    getList() {
      this.loading = true;
      listHirePeople(this.queryParams).then(response => {
        this.hireList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },

    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {

      this.queryParams= {
        pageNum: 1,
        pageSize: 10,
        name: null,
        telephone: null,
        sex:null
      },
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },


    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除招聘信息编号为"' + ids + '"的数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function () {
        return delHirePeople(ids);
      }).then(() => {
        this.getList();
        this.msgSuccess("删除成功");
      })
    },

  }
};
</script>